package com.edu.exam.entity.grading.integration;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 集成日志实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：integration_log</p>
 *
 * <p>存储成绩数据集成的操作日志</p>
 *
 * @author G-09 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class IntegrationLog {

    @Id
    @Column(name = "log_id", length = 64)
    private String logId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "task_id", referencedColumnName = "task_id", foreignKey = @ForeignKey(name = "fk_integration_log_task"))
    private IntegrationTask integrationTask;

    @Column(name = "operation_type", length = 32, nullable = false)
    private String operationType;

    @Column(name = "operation_level", length = 32, nullable = false)
    private String operationLevel;

    @Column(name = "operation_message", columnDefinition = "TEXT")
    private String operationMessage;

    @Column(name = "operation_data", columnDefinition = "TEXT")
    private String operationData;

    @Column(name = "source_system", length = 32)
    private String sourceSystem;

    @Column(name = "user_id", length = 64)
    private String userId;

    @Column(name = "session_id", length = 64)
    private String sessionId;

    @Column(name = "ip_address", length = 45)
    private String ipAddress;

    @Column(name = "user_agent", length = 255)
    private String userAgent;

    @Column(name = "operation_time", nullable = false)
    private LocalDateTime operationTime;

    @Column(name = "execution_time")
    private Integer executionTime; // 执行时间（毫秒）

    @Column(name = "status", length = 32, nullable = false)
    private String status;

    /**
     * 获取关联的任务ID（为了便于查询）
     */
    @Transient
    public String getTaskId() {
        return integrationTask != null ? integrationTask.getTaskId() : null;
    }

}
